From b691f1e4c5dd7449c3ab3cf1da3a061a2f3d5599 Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Tue, 24 May 2016 14:29:52 +0100 Subject: [PATCH] Hash url serialization to ensure hash stability Closes #1710 --- src/cargo/core/source.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index 487e421ea..c32e7227f 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -341,14 +341,17 @@ impl Ord for SourceIdInner { } } +// The hash of SourceId is used in the name of some Cargo folders, so shouldn't +// vary. `as_str` gives the serialisation of a url (which has a spec) and so +// insulates against possible changes in how the url crate does hashing. impl hash::Hash for SourceId { fn hash(&self, into: &mut S) { self.inner.kind.hash(into); match *self.inner { SourceIdInner { kind: Kind::Git(..), ref canonical_url, .. } => { - canonical_url.hash(into) + canonical_url.as_str().hash(into) } - _ => self.inner.url.hash(into), + _ => self.inner.url.as_str().hash(into), } } } -- 2.30.2